package com.itheima.demo.ticket;

public class TicketRunnable implements Runnable{
    private static int ticket = 100;
    private static Object object = new Object();
    @Override
    public void run() {
        while (true) {
            synchronized (object) {
                if (ticket <= 0){
                    System.out.println("票卖完了,明天再来!!!");
                    break;
                }else {
                    try {
                        Thread.sleep(50);
                        System.out.println(Thread.currentThread().getName() + "卖出了第" + ticket + "张票,还剩" + (ticket-1) + "张票");
                        ticket--;
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }

    }
}
